{% extends "../master.html" %}
{% block hfm_css %}
    <style type="text/css">
        .topic-name{
            color: #a1a1a1;
            width: 70%;
            text-align: center;
            background-color: #dbdbdb;
        }
    </style>
{% end %}
{% block page_content %}
<div class="layui-fluid">
    <div class="layui-row">
        <form action="/text_strategy_add" method="post" class="layui-form layui-form-pane">
            <div class="layui-form-item layui-form-input">
                <div class="topic-name">
                    <span>温馨提示: 关键词策略名称和策略描述建立完成后不支持修改</span>
                </div>
                <br>
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>策略名称</label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input" placeholder="策略名唯一不可重复，支持汉字、英文、数字">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    <span class=""></span>  策略描述
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="可对该策略进行简单描述" id="desc" name="desc" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="keyword_list" class="layui-form-label">
                    <span class="x-red">*</span>  关键词输入
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入关键词，多个关键词可使用回车分隔" id="keyword_list" name="keyword_list" class="layui-textarea" required="" lay-verify="required"></textarea>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6" >
                    <button type="reset" class="layui-btn">重置</button>
                </div>
                <div class="layui-col-xs6" align='right'>
                    <button type="submit" class="layui-btn" lay-submit lay-filter="strategy_form" >确认</button>
                </div>
             </div>
        </form>
    </div>
</div>

<script type="text/javascript">
layui.use(['form','layer'], function() {
    $ = layui.jquery;
    var form = layui.form
        , layer = layui.layer;

    //自定义验证规则
    form.verify({
        nikename: function (value) {
            if (value.length < 5) {
                return '昵称至少得5个字符啊';
            }
        }
        , pass: [/(.+){6,12}$/, '密码必须6到12位']
        , repass: function (value) {
            if ($('#L_pass').val() != $('#L_repass').val()) {
                return '两次密码不一致';
            }
        }
    });
    //监听提交
    form.on('submit(strategy_form)', function (data) {
        //发异步，把数据提交给Tronado
        var taskInfo = data.field;
        var postUrl = "/keyword_strategy_add";
        $.ajax({
            url: postUrl,
            type: 'post',
            data: taskInfo,
            beforeSend: function () {
                this.layerTaskAdd = layer.load(0, {shade: [0.5, '#393D49']});
            },
            success: function (data) {
                if (data.status == 'error') {
                    layer.msg(data.msg, {icon: 5});
                } else if (data.status == 'success') {
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 2000
                    }, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    })
                }
            },
            complete: function () {
                layer.close(this.layerTaskAdd)
            }
        });
        return false;
    });
    form.on('checkbox(father)', function(data){
        if(data.elem.checked){
            $(data.elem).parent().siblings('td').find('input').prop("checked", true);
            form.render();
        }else{
           $(data.elem).parent().siblings('td').find('input').prop("checked", false);
            form.render();
        }
    })
})
</script>

{% end %}